/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cse308.entities;

import cse308.GeneralEntity;
import cse308.helper_classes.GeneralTest;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Aaron
 */
@Entity
@Table(catalog = "nchorn", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Assignment.findAll", query = "SELECT a FROM Assignment a"),
    @NamedQuery(name = "Assignment.findByName", query = "SELECT a FROM Assignment a WHERE a.name = :name")})
public class Assignment implements Serializable, GeneralEntity {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(nullable = false, length = 20)
    private String name;
    @Lob
    private byte[] description;
    @OneToMany(mappedBy = "assignmentname")
    private Collection<Studentsample> studentsampleCollection;
    @JoinColumns({
        @JoinColumn(name = "course", referencedColumnName = "course"),
        @JoinColumn(name = "section", referencedColumnName = "section"),
        @JoinColumn(name = "semester", referencedColumnName = "semester")})
    @ManyToOne
    private Courseoffering courseoffering;

    public Assignment() {
        this.studentsampleCollection = new ArrayList();
    }

    public Assignment(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public byte[] getDescription() {
        return description;
    }

    public void setDescription(byte[] description) {
        this.description = description;
    }

    @XmlTransient
    public Collection<Studentsample> getStudentsampleCollection() {
        return studentsampleCollection;
    }

    public void setStudentsampleCollection(Collection<Studentsample> studentsampleCollection) {
        this.studentsampleCollection = studentsampleCollection;
    }

    public Courseoffering getCourseoffering() {
        return courseoffering;
    }

    public void setCourseoffering(Courseoffering courseoffering) {
        this.courseoffering = courseoffering;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (name != null ? name.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Assignment)) {
            return false;
        }
        Assignment other = (Assignment) object;
        if ((this.name == null && other.name != null) || (this.name != null && !this.name.equals(other.name))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cse308.entities.Assignment[ name=" + name + " ]";
    }
    @Override
    public List<List<GeneralEntity>> getAssociatedClasses() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<GeneralEntity> getAssociatedClass(String associated) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void setWithClass(GeneralTest gt) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void testAddClass(GeneralEntity ge) {
        if(ge instanceof Studentsample){
            this.studentsampleCollection.add((Studentsample)ge);
        }
        else if(ge instanceof  Courseoffering){
            this.courseoffering=(Courseoffering)ge;
        }
    }

    @Override
    public void removeClass(GeneralEntity ge) {
        if(ge instanceof Studentsample){
            this.studentsampleCollection.remove((Studentsample)ge);
        }
        else if(ge instanceof  Courseoffering){
            this.courseoffering=null;
        }
    }

    @Override
    public GeneralEntity findCorrespondingEntity() {
        return this;
    }

    @Override
    public String getIdentifier2() {
        return this.name;
    }

    @Override
    public boolean equalsEntity(GeneralEntity entity) {
        return this.equals(entity);
    }

    @Override
    public Object getPK() {
        return this.name;
    }


}
